package com.ewhale.feitengguest.presenter.user.mine;

import com.ewhale.feitengguest.api.ApiHelper;
import com.ewhale.feitengguest.dto.ArticleDetailDto;
import com.ewhale.feitengguest.dto.VersionDto;
import com.ewhale.feitengguest.view.user.mine.SettingView;
import com.simga.library.base.IPresenter;
import com.simga.library.http.APIException;

public class SettingPresenter extends IPresenter {

    public void loadArticleDetails(int id) {
        mView.showProLoading();
        request(1, ApiHelper.USER_API.getArticleDetails(id), id);
    }

    public void checkVersion() {
        mView.showProLoading();
        request(2, ApiHelper.USER_API.getAPPUrl(1), null);
    }
    @Override
    public <T> void onNext(int postCode, T result, Object data) {
        super.onNext(postCode, result, data);
        switch (postCode) {
            case 1:
                ((SettingView) mView).showDetail((ArticleDetailDto) result,(int)data);
                break;
            case 2:
                ((SettingView) mView).showVersion((VersionDto) result);
                break;
        }
    }

    @Override
    public void otherException(int postCode, Object data, APIException e) {
        super.otherException(postCode, data, e);
        mView.showErrorMessage(postCode, e.getCode(), e.getDisplayMessage());
    }

}
